package com.qf.service.dangan_service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.dangan.Person;
import com.qf.dao.dangan_dao.PersonDao;
import com.qf.service.dangan_service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/*
            敲得越多，钱越多！！！
            敲得越多，钱越多！！！
            敲得越多，钱越多！！！
*/
@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonDao personDao;

    @Override
    public PageInfo<Person> findUsers(int pageIndex, int pageSize, String username, String deptname, Date timename) {
        PageHelper.startPage(pageIndex,pageSize);
        HashMap hashMap = new HashMap();
        hashMap.put("uname",username);
        hashMap.put("dname",deptname);
        hashMap.put("tname",timename);
        //为dao传参数，如果比一个多，那就封装在map里传输
        List<Person> users = personDao.findUsers(hashMap);
        PageInfo<Person> usersPageInfo = new PageInfo<>(users);
        return usersPageInfo;
    }

    @Override
    public int addpost(Person users) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        //以固定格式转化为String类型
        String format = simpleDateFormat.format(date);
        Date parse=null;
        try {
            //String转化为date类型
            parse = simpleDateFormat.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        users.setPdate(parse);
        return personDao.addpost(users);
    }

    @Override
    public Person updatepost(int uid) {
        return null;
    }

    @Override
    public int update(Person users) {
        return 0;
    }

    @Override
    public int delete(int uid) {
        return 0;
    }

    @Override
    public int deletes(int[] uid) {
        return personDao.deletes(uid);
    }

    @Override
    public List<Person> findbyids(int[] uid) {
        return personDao.findbyids(uid);
    }

    @Override
    public int updatepassword(String ppassword, Integer pid) {
        HashMap hashMap = new HashMap();
        hashMap.put("pid",pid);
        hashMap.put("ppassword",ppassword);

        return personDao.updatepassword(hashMap);
    }

    @Override
    public Person updateperson(int pid) {
        return personDao.updateperson(pid);
    }

    @Override
    public int updateperson1(Person person) {
        return personDao.updateperson1(person);
    }

    @Override
    public int deletepenson(int pid) {
        return personDao.deletepenson(pid);
    }
}
